# ====================
# 构建前端静态资源
# ====================
FROM harbor.jianmucloud.com:30003/n9e/node:16 as builder

# 设置元信息
LABEL maintainer="ai-liuys@outlook.com" \
      organization="浙江大学 ACES 实验室" \
      project="BridgeKube JOB Frontend"

# 设置 npm 源为腾讯云，加快依赖安装
RUN npm config set registry https://registry.npmmirror.com

# 设置 npm 版本（可选）
ENV NPM_VERSION 6.14.4

# 项目信息
ENV PROJECT_NAME="BridgeKube JOB Frontend" \
    ORGANIZATION="浙江大学 ACES 实验室" \
    CREATED_BY="ai-liuys@outlook.com"

# 添加所有文件并执行构建
ADD . /data

# 设置工作目录
WORKDIR /data
RUN npm i
RUN npm run build


# ====================
# 部署到 Nginx
# ====================
FROM harbor.jianmucloud.com:30003/n9e/nginx:stable-alpine

# 设置元信息
LABEL maintainer="ai-liuys@outlook.com" \
      organization="浙江大学 ACES 实验室" \
      project="BridgeKube JOB Frontend"

# 设置工作目录
WORKDIR /data/job/job-frontend

# 复制前端构建的静态资源到 Nginx 容器
COPY --from=builder /data/dist/index.html /data/job/job-frontend/
COPY --from=builder /data/dist/static /data/job/job-frontend/static
COPY --from=builder /data/dist/js /data/job/job-frontend/js

# 设置时区为 Asia/Shanghai，并创建日志目录
RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    echo 'Asia/Shanghai' > /etc/timezone && \
    mkdir -p /data/job/logs/job-frontend/nginx

# 暴露 Nginx 服务端口
EXPOSE 80

# 设置运行时环境变量
ENV PROJECT_NAME="BridgeKube JOB Frontend" \
    SERVICE_PORT=80 \
    ORGANIZATION="浙江大学 ACES 实验室" \
    CREATED_BY="ai-liuys@outlook.com"

# 启动 Nginx 服务
CMD ["nginx", "-g", "daemon off;"]
